﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Framework;

using System.Data.Objects;

namespace Business.Operations
{
    public class LigOperation
    {
        private static HPDMASEntities db = new HPDMASEntities();

        public LigOperation()
        {

        }

        public static List<Lig> LigGetAll()
        {
            var ligListesi = db.Lig.ToList();
            return ligListesi;
        }

        public static Lig LigGetByLigId(int ligId)
        {
            var lig = (from c in db.Lig where c.LigID == ligId select c).First();
            return lig;
        }

        public static void LigDelete(int ligId)
        {
            Lig k = (from c in db.Lig where c.LigID == ligId select c).First();
            db.DeleteObject(k);
            db.SaveChanges();
        }

        public static void LigInsert(Lig lig)
        {
            db.Lig.AddObject(lig);
            db.SaveChanges();
        }

        public static int LigIdGetByLigAdi(string ligAdi)
        {
            var ligId = (from c in db.Lig where c.LigAdi == ligAdi select c.LigID).First();
            return ligId;
        }

        public static List<string> LigAdiGetAll()
        {
            var ligAdi = db.LigSehir.
                Select(c => c.Lig.LigAdi).ToList();
            return ligAdi;
        }

        public static List<Lig> LigGetBySehirId(int sehirId)
        {
            var lig = db.LigSehir.
                Where(c => c.SehirID == sehirId).
                Select(c=>c.Lig).ToList();
            return lig;
        }

        public static List<string> LigAdiGetBySehirId(int sehirId)
        {
            var lig = db.LigSehir.
                Where(c => c.SehirID == sehirId).
                Select(c => c.Lig.LigAdi).ToList();
            return lig;
        }
    }
}
